<?php
html::printPath(
    array('orgSeminar.form-title' => '/org/orgSeminar/all', $seminar['name'] => '/org/orgSeminar/display?id=' . $seminar['id'], 'paymentAcceptance.form-title' => ''),
    'paymentAcceptance.form-desc'
);
$msg->printMessages();

echo '<em>' . text::getEscaped('seminar.entity') . ': </em>' .
        $seminar['name'] . ', ' .
        format::date($seminar['begin_date']) . ' &ndash; ' . format::date($seminar['end_date']) . ', ' .
        text::get('seminar.active') . ': ' . format::boolean($seminar['active']);

echo '<h3>' . text::getEscaped('paymentAcceptance-editRules') . '</h3>';

echo text::getEscaped('paymentAcceptance-editRules-info');
echo '<ul>';
echo '<li>' . text::getEscaped('paymentAcceptance-editRule-1') . '</li>';
echo '<li>' . text::getEscaped('paymentAcceptance-editRule-2') . '</li>';
echo '<li>' . text::getEscaped('paymentAcceptance-editRule-3') . '</li>';
echo '</ul>';

$fb = new FormBuilder('paymentAcceptance', $paymentAcceptance);
$fb->hidden('seminar_id');
$fb->date('deadline')
        ->required()->labelKey('paymentAcceptance.deadline')->hint();
$fb->yesNoBox('accepts_cash')->noEmptyOption()->required()->onChange('acceptsCashChanged()')
        ->disabled(
                 $paymentAcceptance[sql::$ENTITY_VERSION_KEY] != NULL &&
                 $paymentAcceptance['accepts_cash'] == sql::$TRUE &&
                 $seminar['active'] == sql::$TRUE);
$fb->textarea('cash_notes')->hint()->required()->disabled($paymentAcceptance['accepts_cash'] != 1);
$fb->delimiter();
$fb->yesNoBox('accepts_bank_transfer')->noEmptyOption()->required()->onChange('acceptsBankTransferChanged()')
        ->disabled(
                $paymentAcceptance[sql::$ENTITY_VERSION_KEY] != NULL &&
                $paymentAcceptance['accepts_bank_transfer'] == sql::$TRUE &&
                $seminar['active'] == sql::$TRUE);
$fb->combobox('bank_account_id', $bankAccountOptions)->required()
        ->disabled(
                ($seminar['active'] == sql::$TRUE && $paymentAcceptance[sql::$ENTITY_VERSION_KEY] != NULL) ||
                $paymentAcceptance['accepts_bank_transfer'] != sql::$TRUE);
$fb->text('variable_symbol')->required()
        ->disabled(
                ($seminar['active'] == sql::$TRUE && $paymentAcceptance[sql::$ENTITY_VERSION_KEY] != NULL) ||
                $paymentAcceptance['accepts_bank_transfer'] != sql::$TRUE);
$fb->textarea('bank_transfer_notes')
        ->disabled($paymentAcceptance['accepts_bank_transfer'] != sql::$TRUE);
$fb->submitButton();
$fb->write();
?>
<script type="text/javascript">
    var noValue = '<?php echo sql::$FALSE ?>';
    function acceptsCashChanged() {
        var acceptsCash = document.getElementById('accepts_cash');
        // $('#accepts_cash').closest('tr').next().toggle();
        document.getElementById('cash_notes').disabled = acceptsCash.value == noValue;
    }

    function acceptsBankTransferChanged() {
        var acceptsCash = document.getElementById('accepts_bank_transfer');
        // $('#accepts_cash').closest('tr').next().toggle();
        var disabled = acceptsCash.value == noValue;
        document.getElementById('bank_account_id').disabled = disabled;
        document.getElementById('variable_symbol').disabled = disabled;
        document.getElementById('bank_transfer_notes').disabled = disabled;
    }
</script>